package com.wuxy.request;

import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.wuxy.util.FaceUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName MeetFace
 * @Description TODO
 * @Author wuxy
 * @DateTime 2018/9/25 09:21
 **/
public class MeetFaceRequest {
    public static String doPost(String url, String appid, String apiKey,String jsonParam, String firstImg, String secondImg){
        try {
            Map<String, String> headers = FaceUtil.getHeaders(appid, apiKey,jsonParam);
            Map<String, Object> param = new HashMap<>();
            param.put("first_image", firstImg);
            param.put("second_image", secondImg);
            HttpResponse<JsonNode> jsonResponse = Unirest.post(url)
                    .headers(headers)
                    .fields(param)
                    .asJson();
            System.out.println(jsonResponse.getBody().toString().substring(18,37));
            return jsonResponse.getBody().toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "111";
    }

    public static void main(String[] args) {
        String img1= FaceUtil.readimg("E://img/zl.jpg");
        String img2=FaceUtil.readimg("E://img/gzc.jpg");
        System.out.println("周雷和高子超的相似度：");
        doPost("http://api.xfyun.cn/v1/service/v1/image_identify/face_verification",
                "5ba44a7c",
                "ce6dd55cce2839fad84ca4639664183b",
                "{\"auto_rotate\": true}",
                img1,
                img2);

    }
}
